package com.test.pudamoney.view_pudamoney.info_input_pudamoney;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.test.pudamoney.R;
import com.test.pudamoney.bean_pudamoney.process_pudamoney.ProcessData_pudamoney;
import com.test.pudamoney.dialog_pudamoney.AddressSelectDialog_Niri_pudamoney;
import com.test.pudamoney.util_pudamoney.StringUtil_pudamoney;
import com.test.pudamoney.view_pudamoney.base_pudamoney.BaseInfoInputViewManager_pudamoney;


public class AddressPickViewManager_Niri_pudamoney extends BaseInfoInputViewManager_pudamoney {

    private TextView titleTv;
    private TextView inputTv;
    private View clickView;

    private AddressSelectDialog_Niri_pudamoney addressSelectDialog;

    private String state, city, area;

    public AddressPickViewManager_Niri_pudamoney(View view, ProcessData_pudamoney data){
        super(view,data);
    }

    @Override
    protected void init(){

        titleTv = mView.findViewById(R.id.view_address_pick_tv_title);
        inputTv = mView.findViewById(R.id.view_address_pick_tv_input);
        clickView = mView.findViewById(R.id.view_address_pick_layout_click);

        setTitle(mData.getTitle());
        inputTv.setHint(mData.getHint());

        clickView.setOnClickListener(v -> new AddressSelectDialog_Niri_pudamoney(mView.getContext(), inputTv, addressStrs -> {
            if (addressStrs.length<3) return;
            state = addressStrs[0];
            city = addressStrs[1];
            area = addressStrs[2];
        }).show());

    }


    @Override
    public boolean checkInput() {
        if (!mData.isMustInput()) return true;
        return (!TextUtils.isEmpty(state))&&(!TextUtils.isEmpty(city))&&(!TextUtils.isEmpty(area));
    }

    @Override
    public String getInput() {
        return "";
    }

    public void setTitle(String title){
        if (TextUtils.isEmpty(title)) titleTv.setVisibility(GONE);
        else {
            titleTv.setVisibility(VISIBLE);
            titleTv.setText(title);
        }
    }

    public String getState() {
        return StringUtil_pudamoney.getSafeString(state);
    }

    public String getCity() {
        return StringUtil_pudamoney.getSafeString(city);
    }

    public String getArea() {
        return StringUtil_pudamoney.getSafeString(area);
    }
}
